<html>
<head>
	<meta charset="UTF-8">
	<title>图片自动上传COS</title>
</head>
<body>
	
<p>查看控制台...</p>
<button onclick="start()">开始</button>

</body>
<script type="text/javascript">

/* 图片上传COS记录：
	Goodsup		pad_goodsup		image_up
	Goodsup		pad_goodsup		image
	Seek		pad_seek		image
	Seek		pad_seek		image2
	Seek		pad_seek		image3
	Supply		goods			image
	Goods		goods			image
	Goods		goods			image_up
 */
let data = {
	model: 'Goods',
	dir: 'goods',
	img_field: 'image_up',
	save_step: 10,
};
let d = null;
function one_request(){
	//原生JS实现ajax（post）
	//步骤一:创建异步对象
	var ajax = new XMLHttpRequest();
	//步骤二:设置请求的类型及url，传参数
	ajax.open('post', "http://oas.biuyum.com/chain/autoloop/imgtocos/");
	// ajax.open('post', "http://oa.qiqiao.com/chain/autoloop/imgtocos/");
	//post请求一定要添加请求头才行不然会报错
	ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	d = new Date();
	console.log("send : =========================================== " + d.toLocaleString());
	//将数据data进行处理，将数据转化成send()想要的数据
	var str = '';
	var f = '';
	for(var i in data){
		str += f + i + "=" + data[i];
		f = '&';
	}
	//步骤三:发送请求传参数
	ajax.send(str);
	//步骤四:注册事件 onreadystatechange 状态改变就会调用
	ajax.onreadystatechange = function () {
		if (ajax.readyState==4 &&ajax.status==200) {
			//步骤五 如果能够进到这个判断 说明 数据 完美的回来了,并且请求的页面是存在的
			d = new Date();
			console.log(ajax.responseText + " ===== " + d.toLocaleString());
		}
	}
}

function start(){
	one_request();
	setInterval(one_request, 5 * 1000);
}



</script>
</html>